package com.csun.nusing.ui.fragment;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.csun.nusing.R;
import com.csun.nusing.presenter.FragmentNursingHomePresenter;
import com.csun.nusing.presenter.inter.IHome;
import com.csun.nusing.ui.activity.AlarmListActivity;
import com.csun.nusing.ui.activity.DeviceListActivity;
import com.csun.nusing.ui.activity.HealthListActivity;
import com.csun.nusing.ui.activity.OldrestDetailsActivity;
import com.csun.nusing.ui.myview.RoundImageView;
import com.csun.nusing.ui.myview.TabLayout;

/**
 * 护士界面的第一个主界面 ClassName: NursingHomeFragment
 * 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-19
 */
public class NursingHomeFragment extends
		BaseFragment<FragmentNursingHomePresenter> implements IHome {

	private LinearLayout devicell;
	private LinearLayout alarmll;
	private LinearLayout healthll;
	private LinearLayout oldsterll;
	private TextView bloodoxyTv;
	private TextView bloodpressTv;
	private TextView bloodsugerTv;
	private TextView heartrateTv;
	private TextView huxiTv;
	private TextView temperatureTv;
	private RoundImageView photoimageView;
	private TextView nameTv;
	private String oldId;
	private String oldpicId;
	private String oldName;
	private TabLayout mTabLayout;
	public String olderPhotopath;
	public String olderBir;
	public String olderSex;
	public String olderEcgname;
	public String olderEcgPhone;
	private String olderage;
	private String roomBed;
	private String roomid;

	public NursingHomeFragment() {
	}

	public static NursingHomeFragment newInstance() {
		return new NursingHomeFragment();
	}

	@Override
	public int getContentViewId() {
		return R.layout.fragment_nursing_home;
	}

	// findView
	@Override
	public void initSubViews(View view) {
		super.initSubViews(view);
		findView(view);
		controlView();
	}

	private void controlView() {
	}

	/**
	 * 控件
	 * 
	 * @Description: TODO
	 * @param @param view
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-10-20
	 */
	private void findView(View view) {
		mTabLayout = view
				.findViewById(R.id.fragment_nursinghome_tl_tab);
		devicell = view
				.findViewById(R.id.fragment_nursinghome_device_ll);
		alarmll = view
				.findViewById(R.id.fragment_nursinghome_alarm_ll);
		healthll = view
				.findViewById(R.id.fragment_nursinghome_health_ll);
		oldsterll = view
				.findViewById(R.id.fragment_nursinghome_oldster_ll);
		bloodoxyTv = view
				.findViewById(R.id.item_viewpager_bloodoxy_tv);
		bloodpressTv = view
				.findViewById(R.id.item_viewpager_bloodpress_tv);
		bloodsugerTv = view
				.findViewById(R.id.item_viewpager_bloodsuger_tv);
		heartrateTv = view
				.findViewById(R.id.item_viewpager_heartrate_tv);
		huxiTv = view.findViewById(R.id.item_viewpager_huxi_tv);
		temperatureTv = view
				.findViewById(R.id.item_viewpager_temperature_tv);
		photoimageView = view
				.findViewById(R.id.item_viewpager_headphoto_iv);
		nameTv = view.findViewById(R.id.item_viewpager_name_tv);

		devicell.setOnClickListener(new click());
		alarmll.setOnClickListener(new click());
		healthll.setOnClickListener(new click());
		oldsterll.setOnClickListener(new click());

	}

	/**
	 * 点击事件的监听 ClassName: click
	 * 
	 * @Description: TODO
	 * @author fzq
	 * @date 2017-10-22
	 */
	private class click implements OnClickListener {
		@Override
		public void onClick(View v) {
			Intent intent = null;
			switch (v.getId()) {
			case R.id.fragment_nursinghome_device_ll:
				intent = new Intent(getActivity(), DeviceListActivity.class);
				startActivity(intent);
				break;
			case R.id.fragment_nursinghome_alarm_ll:
				if (oldId != null) {
					// 单个老人的报警
					intent = new Intent(getActivity(), AlarmListActivity.class);
					intent.putExtra("olderId", "" + oldId);
					intent.putExtra("oldName", "" + oldName);
					intent.putExtra("oldpicId", "" + oldpicId);
					startActivity(intent);
				}
				break;
			case R.id.fragment_nursinghome_health_ll:
				if (oldId != null) {

					// 单个老人的健康数据
					// 老人详情界面
					intent = new Intent(getActivity(),
							HealthListActivity.class);
					intent.putExtra("olderId", "" + oldId);
					startActivity(intent);
				}
				break;
			case R.id.fragment_nursinghome_oldster_ll:
				if (oldId != null) {
					intent = new Intent(getActivity(),
							OldrestDetailsActivity.class);
					intent.putExtra("olderId", "" + oldId);
					intent.putExtra("olderName", "" + oldName);
					intent.putExtra("olderPhotopath", "" + olderPhotopath);
					intent.putExtra("olderBir", "" + olderBir);
					intent.putExtra("roomId", "" + roomid);
					intent.putExtra("olderSex", "" + olderSex);
					intent.putExtra("olderage", "" + olderage);
					intent.putExtra("roombed", "" + roomBed);
					intent.putExtra("olderEcgname", "" + olderEcgname);
					intent.putExtra("olderEcgPhone", "" + olderEcgPhone);
					startActivity(intent);
				}
				break;
			default:
				break;
			}
		}
	}

	// 交给presenter处理数据逻辑
	@Override
	public void initData() {
		super.initData();
		mPresenter.getOlderList(getActivity(), mTabLayout, bloodoxyTv,
				bloodpressTv, bloodsugerTv, heartrateTv, huxiTv, temperatureTv,
				photoimageView, nameTv);
	}

	@Override
	protected FragmentNursingHomePresenter getPresenter() {
		return new FragmentNursingHomePresenter(this);
	}

	/**
	 * 回调老人的id
	 */
	@Override
	public void sendId(String id, String name, String picpath, String bir,
			String age, String roombed, String sex, String egname,
			String egphone,String roomId,String bedNo) {
		oldId = id;
		oldName = name;
		olderPhotopath = picpath;
		olderage = age;
		roomBed = roombed;
		olderBir = bir;
		olderSex = sex;
		olderEcgname = egname;
		olderEcgPhone = egphone;
		roomid = roomId;
	}

}
